package com.pzh.assignment.common.bean.vo;

import com.pzh.assignment.common.bean.GlobalConstant;
import com.pzh.assignment.entity.User;
import lombok.Data;

import java.time.format.DateTimeFormatter;

@Data
public class AccountVO {
    private Integer id;

    private String account;

    private String username;

    private String email;

    private String phone;

    private Integer roleId;

    private Integer groupId;

    private String createTime;

    private String updateTime;

    public static AccountVO valueOf(User user) {
        AccountVO vo = new AccountVO();
        vo.setId(user.getId());
        vo.setAccount(user.getAccount());
        vo.setUsername(user.getUsername());
        vo.setEmail(user.getEmail());
        vo.setPhone(user.getPhone());
        vo.setRoleId(user.getRoleId());
        vo.setGroupId(user.getGroupId());
        if (user.getCreateTime() != null) {
            vo.setCreateTime(user.getCreateTime().format(DateTimeFormatter.ofPattern(GlobalConstant.DATE_FORMAT_PATTERN)));
        }
        if (user.getUpdateTime() != null) {
            vo.setUpdateTime(user.getUpdateTime().format(DateTimeFormatter.ofPattern(GlobalConstant.DATE_FORMAT_PATTERN)));
        }
        return vo;
    }

}
